<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta charset="UTF-8">
	<title>新增订单</title>
	<meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />

 <!-- 新模板 -->
<link rel="shortcut icon" href="<c:url value='/template/new_muban/images/favicon.ico'/>" type="image/x-icon"/>

<!-- 最新导入 -->
<script type="text/javascript" src="<c:url value='/template/new_muban/js/jquery-min-1.7.js'/>"></script>
<link rel="stylesheet" href="<c:url value='/template/new_muban/css/font.css'/>">
<link rel="stylesheet" href="<c:url value='/template/new_muban/css/xadmin.css'/>">   
<script src="<c:url value='/template/new_muban/lib/layui/layui.js'/>" charset="utf-8"></script> 
<script type="text/javascript" src="<c:url value='/template/new_muban/js/xadmin.js'/>"></script>

<style type="text/css">
	/*圆形头像  */
	/* #divcss5{ margin:10px auto}  */
	#divcss5 img{ border-radius:50%} 
	.x-so input.layui-input {
    	width: 150px;
	}
</style>
</head>
<body>
   
     <div class="x-body">
     
     
         <form class="layui-form"> 
     
     <%-- <div class="layui-form-item">
      <span class="x-red">*</span><label class="layui-form-label">选择车型</label>
      <div class="layui-input-inline">
        <select id="g_id" name="modules" lay-verify="required" lay-search="">
          <option value="">请输入车型名称</option>
          <c:forEach items="${allCar}" var="car">
      		<option  value="${car.id}">${car.name}(${car.cx_fullname})</option>
          </c:forEach>
        </select>
      </div>
       
    </div> --%>
     
     
     <div class="layui-form-item">
              <label for="username" class="layui-form-label">
                  <span class="x-red">*</span>选择车型
              </label>
              <div class="layui-input-inline">
                  <select id="g_id" name="modules" lay-verify="required" lay-search="">
          <option value="">请输入车型名称</option>
          <c:forEach items="${allCar}" var="car">
      		<option  value="${car.gttl_id}">${car.gttl_name}(${car.gslal_name})</option>
          </c:forEach>
        </select>
              </div>
              <div class="layui-form-mid layui-word-aux">
                  <span class="x-red">*</span>想要车型  : ${clue.car_name}
              </div>
          </div>
     
          <div class="layui-form-item">
              <label for="username" class="layui-form-label">
                  <span class="x-red">*</span>姓名
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="ho_name" name="ho_name" value="${clue.c_name}" required="" lay-verify="required"
                  autocomplete="off" class="layui-input">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="username" class="layui-form-label">
                  <span class="x-red">*</span>电话
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="ho_phone" name="ho_phone" value="${clue.c_phone}" required="" lay-verify="required"
                  autocomplete="off" class="layui-input">
              </div>
          </div>
           <div class="layui-form-item">
              <label for="username" class="layui-form-label">
                  <span class="x-red">*</span>价格
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="ho_price" name="ho_price"  onkeyup="clearNoNum(this)" value="${clue.gttl_saleprice}" required="" lay-verify="required"
                  autocomplete="off" class="layui-input">
              </div>
          </div>
           <div class="layui-form-item">
              <label for="username" class="layui-form-label">
                  定金
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="ho_pre_money" name="ho_pre_money"  onkeyup="clearNoNum(this)" 
                  autocomplete="off" class="layui-input">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="username" class="layui-form-label">
                  收货地址
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="ho_address" name="ho_address"
                  autocomplete="off" class="layui-input">
              </div>
          </div>
          
          
          
          
          
          
          
           <!-- <div class="layui-form-item">
              <label for="username" class="layui-form-label">
                  <span class="x-red">*</span>购车方式
              </label>
              <div class="layui-input-inline">
                  <select id="shipping" name="shipping" class="valid">
                    <option value="shentong">分期</option>
                    <option value="shunfeng">全款</option>
                  </select>
              </div>
          </div>  -->
     
          <div class="layui-form-item layui-form-text">
              <label for="desc" class="layui-form-label">
                订单备注
              </label>
              <div class="layui-input-block">
                  <textarea placeholder="请输入内容" id="ho_desc" name="ho_desc" class="layui-textarea"></textarea>
              </div>
          </div>
          
           <div class="layui-form-item">
    <label class="layui-form-label">购车方式</label>
    <div class="layui-input-block">
      <input type="radio" lay-filter="ho_type" name="ho_type" value="0" title="分期">
      <input type="radio" lay-filter="ho_type" name="ho_type" value="1" title="全款" checked>
    </div>
  </div>
  
  
  <div class="layui-form-item">
    <label class="layui-form-label">店内保险</label>
    <div class="layui-input-block">
      <input type="radio" lay-filter="ho_bx" name="ho_bx" value="0" title="否" checked>
      <input type="radio" lay-filter="ho_bx" name="ho_bx" value="1" title="是" >
    </div>
  </div>
  <div class="layui-form-item">
              <label for="username" class="layui-form-label">
                  保险公司
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="ho_bx_name" name="ho_bx_name"
                  autocomplete="off" class="layui-input">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="username" class="layui-form-label">
               保险价格
              </label>
              <div class="layui-input-inline">
                    <input type="text" id="ho_bx_money" name="ho_bx_money"  onkeyup="clearNoNum(this)" 
                  autocomplete="off" class="layui-input">
              </div>
          </div>
          
           <div class="layui-form-item">
              <label for="username" class="layui-form-label">
        到期时间    
              </label>
              <div class="layui-input-inline">
                   <input class="layui-input"   autocomplete="off" placeholder="保险到期时间" name="end" id="end" readonly>
              </div>
              </div>
         
  <div class="layui-form-item">
              <label for="username" class="layui-form-label">
               贷款金额
              </label>
              <div class="layui-input-inline">
                    <input type="text" id="ho_dk_all_money" name="ho_dk_all_money"  onkeyup="clearNoNum(this)" 
                  autocomplete="off" class="layui-input">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="username" class="layui-form-label">
              首付金额
              </label>
              <div class="layui-input-inline">
                    <input type="text" id="ho_dk_one_money" name="ho_dk_one_money"  onkeyup="clearNoNum(this)" 
                  autocomplete="off" class="layui-input">
              </div>
          </div>
          
          <div class="layui-form-item">
              <label for="username" class="layui-form-label">
                  贷款状态
              </label>
              <div class="layui-input-inline">
                  <select id="ho_dk_status" name="ho_dk_status" class="valid">
                    <option value="0">待提交材料</option>
                    <option value="1">审核中</option>
                    <option value="2">已放款</option>
                  </select>
              </div>
          </div> 
           <div class="layui-form-item">
              <label for="username" class="layui-form-label">
                  支付状态
              </label>
              <div class="layui-input-inline">
                  <select id="ho_pay_status" name="ho_pay_status" class="valid">
                    <option value="0">未付款</option>
                    <option value="1">付定金</option>
                    <option value="2">首付支付</option>
                     <option value="3">全款支付</option>
                  </select>
              </div>
          </div> 
           <div class="layui-form-item">
              <label for="username" class="layui-form-label">
                  车状态
              </label>
              <div class="layui-input-inline">
                  <select id="ho_car_status" name="ho_car_status" class="valid">
                    <option value="0">现车</option>
                    <option value="1">预定中</option>
                    <option value="2">待提车</option>
                    <option value="3">已交付</option>
                  </select>
              </div>
          </div> 
          
          
  
          
          <div class="layui-form-item">
              <label for="L_repass" class="layui-form-label">
              </label>
              <button  class="layui-btn" lay-filter="add" lay-submit="">
                  生成
              </button>
          </div>
      </form>
    </div>
    <script>
    layui.use('laydate', function(){
        var laydate = layui.laydate;
        
        //执行一个laydate实例
        laydate.render({
          elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
          elem: '#end' //指定元素
        });
        //执行一个laydate实例
        laydate.render({
      	  type: 'time'
      		    ,format: 'HH:mm:ss'
          ,elem: '#end_time' //指定元素
        });
      });
        layui.use(['form','layer'], function(){
            $ = layui.jquery;
          var form = layui.form
          ,layer = layui.layer;
          
          
          
        
          //自定义验证规则
          form.verify({
            nikename: function(value){
              if(value.length < 5){
                return '昵称至少得5个字符啊';
              }
            }
            ,pass: [/(.+){6,12}$/, '密码必须6到12位']
            ,repass: function(value){
                if($('#L_pass').val()!=$('#L_repass').val()){
                    return '两次密码不一致';
                }
            }
          });

          var flag = "A";
          form.on('radio(ho_type)', function(data){
			    //console.log(data.elem); //得到radio原始DOM对象
			    console.log(data.value); //被点击的radio的value值
			     if(data.value==0){
			     	    flag = "B";
			     }
			   
			     
			}); 
          
          var ho_bx_flag = "A";
          form.on('radio(ho_bx)', function(data){
			    //console.log(data.elem); //得到radio原始DOM对象
			    console.log(data.value); //被点击的radio的value值
			     if(data.value==1){
			    	 ho_bx_flag = "B";
			     }
			   
			     
			}); 

          
          
          
          //监听提交
          form.on('submit(add)', function(data){
            console.log(data);
            console.log( JSON.stringify(data.field));
           //付款方式
           //var ho_type = JSON.stringify(data.field.ho_type);
           var ho_type = 1;
           console.log("ho_type : "+ho_type);
           console.log("flag : "+flag);
           if(flag == "B"){
        	   ho_type = 0;
           }
           
           //订单推荐人last_id
             var last_id = "${clue.last_uid}";
           //上一级fx_p_id
             var fx_p_id = "${clue.p_id}";
           
            //车的id
            //var g_id = "${clue.c_car}";
          	var g_id = $("#g_id").val();
            //车的名称
            //var g_name = "${clue.name}";
            var g_name = $("#g_id").find("option:selected").text();
           
            console.log("g_id : "+g_id + "  g_name  : "+g_name );
            
            //线索id
             var c_id = "${clue.c_id}";
            //订单备注
            var ho_desc = $("#ho_desc").val();
            //收货地址
            var ho_address = $("#ho_address").val();
        	//订单状态
        	var ho_status = 0;
        	 //定金
        	var ho_pre_money = $("#ho_pre_money").val();
        	if(ho_pre_money == "" || ho_pre_money ==0 || ho_pre_money == null){
        		ho_pre_money == 0;
        	} 
        	//订单价格
        	var ho_price = $("#ho_price").val();
        	//购车人id
        	var u_id = "${clue.u_id}";
        	//姓名
            var ho_name = $("#ho_name").val();
        	//电话
        	  var ho_phone = $("#ho_phone").val();
        	 
        	//店内保险
              var ho_bx = 0;
              console.log("ho_bx : "+ho_bx);
              console.log("ho_bx_flag : "+ho_bx_flag);
              if(ho_bx_flag == "B"){
            	  ho_bx = 1;
              }
              
              
              //保险公司
              var ho_bx_name = $("#ho_bx_name").val();
        	//保险价格
        	 var ho_bx_money = $("#ho_bx_money").val();
        	if(ho_bx_money == "" || ho_bx_money == null){
        		ho_bx_money = 0;
        	}
        	//保险到期时间
        	 var ho_bx_endtime = $("#end").val();
        	//贷款金额
        	 var ho_dk_all_money = $("#ho_dk_all_money").val();
        	 if(ho_dk_all_money == "" || ho_dk_all_money == null){
        		 ho_dk_all_money = 0;
         	}
        	//贷款首付金额
        	 var ho_dk_one_money = $("#ho_dk_one_money").val();
        	 if(ho_dk_one_money == "" || ho_dk_one_money == null){
        		 ho_dk_one_money = 0;
         	}
        	//贷款状态
        	var ho_dk_status = $("#ho_dk_status").val();
        	 
        	 //付款状态
        	 var ho_pay_status = $("#ho_pay_status").val();
        	 
        	 //车状态
        	 var ho_car_status = $("#ho_car_status").val();
        	 
        //	return false;
        	  $.ajax({
	                type: 'POST',
	                url: "<c:url value='/addOrder.do'/>",
			     	async : false, // 注意此处需要yi步  
		    		data: {
		 	   			"last_id":last_id,"fx_p_id":fx_p_id,"g_id":g_id,"g_name":g_name,"c_id":c_id,"ho_desc":ho_desc,"ho_address":ho_address,
		 	   				"ho_status":ho_status,"ho_pre_money":ho_pre_money,"ho_price":ho_price,"u_id":u_id,
		 	   				"ho_name":ho_name,"ho_phone":ho_phone,"ho_type":ho_type,"ho_bx":ho_bx,"ho_bx_name":ho_bx_name,
		 	   				"ho_bx_money":ho_bx_money,"ho_bx_endtime":ho_bx_endtime,"ho_dk_all_money":ho_dk_all_money,"ho_dk_one_money":ho_dk_one_money,
		 	   				"ho_dk_status":ho_dk_status,"ho_pay_status":ho_pay_status,
		 	   			"ho_car_status":ho_car_status
		    		},
			        success: function(data){		
						if (data == 0) {
		             	   layer.msg('生成失败!',{icon: 2,time:3000});      
		                    return false;
		                } else if(data ==1)  {
		
		                	  layer.msg("生成成功", {icon: 6,time:1000},function () {
		                          // 获得frame索引
		                          var index = parent.layer.getFrameIndex(window.name);
		                          //alert(index);
		                          //关闭当前frame
		                          parent.layer.close(index);
		                          //重新加载父页面
		                          parent.location.reload();
		                      });
				           }
	             
	                }
				});
        	
            return false;
          });
          
          
        });
    </script>
     <script type="text/javascript">
//小数验证
	function clearNoNum(obj){  
     //修复第一个字符是小数点 的情况.  
     if(obj.value !=''&& obj.value.substr(0,1) == '.'){  
         obj.value="";  
     }  
     obj.value = obj.value.replace(/^0*(0\.|[1-9])/, '$1');//解决 粘贴不生效  
     obj.value = obj.value.replace(/[^\d.]/g,"");  //清除“数字”和“.”以外的字符  
     obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的       
     obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");      
     obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');//只能输入两个小数       
     if(obj.value.indexOf(".")< 0 && obj.value !=""){//以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额  
         if(obj.value.substr(0,1) == '0' && obj.value.length == 2){  
             obj.value= obj.value.substr(1,obj.value.length);      
         }  
     }      
 }    
 </script>       
  </body>
</html>